package com.database.mapper;

import com.database.character.Post;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface PostMapper {

  //查询所有帖子
  @Select("select * from post  order by create_time desc")
  List<Post> list();

  //查询特定用户发布的帖子
  @Select("select * from post where user_id = #{userId}")
  List<Post> getPostByUid(Integer userId);

  //新增帖子
  @Insert("insert into post(content, create_time, update_time, user_id, title, search_content) " +
    " values (#{content}, #{createTime}, #{updateTime}, #{userId}, #{title}, #{searchContent})")
  int addPost(Post post);

  //删除帖子
  @Delete("delete from post where post_id = #{postId}")
  int deletePostByPid(Integer postId);

  //修改帖子
  int updatePost(Post post);

  //根据postId查找帖子
  @Select("select * from post where post_id = #{postId}")
  Post getPostByPid(Integer postId);

  //给予帖子标题和内容的模糊搜索

  @Select("select * from post where MATCH(title,search_content) AGAINST(#{search})")
  List<Post> getPostBySearch(String search);

  @Select("select * from post where user_id in (select focused_id from attention where user_id = #{userId}) order by create_time desc")
  List<Post> getAttention(Integer userId);
}
